package com.googlecode.tda367.denty.view;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import com.googlecode.tda367.denty.core.data.GameData;


public class HUDView {

	private Image lifeIndicator;
	private Image blockIndicator;
	private GameData gameData;
	private static HUDView instance;

	
	private HUDView() {
		this.gameData = GameData.getInstance();
	}
	
	public static HUDView getInstance() {
		if (instance == null) {
			instance = new HUDView();
		}
		return instance;
	}

	public void render(GameContainer container, Graphics g) {
		
		// Render HP-bar.
		g.setColor(Color.white);
		g.fillRect(100, 10, 104, 20);
		int hp = gameData.getHP();
		if (hp > 0 ) {
			if(hp <= 25) {
				g.setColor(Color.red);
			} else if (hp <= 50) {
				g.setColor(Color.orange);
			} else if(hp <= 75) {
				g.setColor(Color.yellow);
			} else {
				g.setColor(Color.green);
			}
			g.fillRect(102, 12, hp, 16);
		}
		g.setColor(Color.white);
		
		int blocks = gameData.getBlocks();
		// Render Life and block indicator
		g.drawImage(this.blockIndicator, 210, 10);
		g.drawString(blocks + "", 234, 10);
		g.drawImage(lifeIndicator, 258, 10);
		int lives = gameData.getLives();
		g.drawString( lives + "", 282, 10);
	}

	public void init() throws SlickException {
		this.lifeIndicator = new Image("res/img/denty-indicator.png");
		this.blockIndicator = new Image("res/img/block-indicator.png");		
	}
}
